<script setup>
import { reactive, computed } from "vue";
import { useRoute,useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

const tags = reactive([
  {
    key: 1,
    name: '精选',
    url: '/selected'
  },
  {
    key: 2,
    name: '歌单大厅',
    url: '/playList'
  },
  {
    key: 3,
    name: '排行榜',
    url: '/ranking'
  },
  {
    key: 4,
    name: '歌手',
    url: '/songs'
  },
  {
    key: 5,
    name: 'VIP',
    url: '/vip'
  },
])

const tagActive = computed(() => {
  return route.meta.tagId
})
// 切换界面
const toPage = (item) => {
  if(tagActive.value === item.key) {
    return 0
  }
  router.push({
    path: item.url
  })
}
</script>

<template>
  <div class="tags">
    <div v-for="item in tags" :key="item.key" class="tag-item" @click="toPage(item)">
      <span :class="`tag-item-box${tagActive === item.key ? '_active' : ''}`">
        {{ item.name }}
        <img v-if="tagActive === item.key" class="tag-item-image animate__animated animate__rubberBand" src="../../../assets/yinfu.png" alt="yinfu"/>
      </span>
    </div>
  </div>
</template>

<style scoped lang="scss">
@mixin boxCenter {
  display: flex;
  justify-content: center;
  align-items: center;
}
.tags {
  width: 100%;
  display: flex;
  margin-bottom: 24px;
}
.tag-item {
  flex: 1;
  height: 40px;
  font-size: 14px;
  letter-spacing: 1px;
  cursor: pointer;
  @include boxCenter;
  position: relative;
}
.tag-item-box{
  z-index: 1;
  color: #333333;
  position: absolute;
}
.tag-item-box_active {
  color: #000000;
  font-weight: bold;
  z-index: 1;
  transition: all .5s;
  position: absolute;
}
.tag-item-image {
  width: 20px;
  height: 26px;
  position: absolute;
  right: -14px;
  top: 6px;
}
</style>
